import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

public class ManagerFile {

    public ManagerFile()   {
        File mfile = new File("manager.txt");
        if(!mfile.exists())
        {
            try {
                mfile.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public void updatePwd()  {
        Scanner in = new Scanner(System.in);
        FileWriter fw = null;
        try {
            fw = new FileWriter("manager.txt");
            System.out.println("请更新的密码");
            String pwd = in.nextLine();
            fw.append(pwd);
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void inputTeacher(){
        Scanner in = new Scanner(System.in);
        TeacherFile teacherFile = new TeacherFile();
        ArrayList arrayList=teacherFile.getArrayList();
        System.out.println("请输入姓名");
        String name = in.nextLine();
        System.out.println("请输入用户账号");
        String user = in.nextLine();
        System.out.println("请输入用户密码");
        String pwd  = in.nextLine();
        Teacher teacher = new Teacher(name,user,pwd);
        arrayList.add(teacher);
        teacherFile.SaveTeacherFile(arrayList);
    }

    public void updateTeacher()
    {
        Scanner in = new Scanner(System.in);
        TeacherFile teacherFile = new TeacherFile();
        ArrayList arrayList = teacherFile.getArrayList();
        System.out.println("请输入需要修改的老师姓名");
        String name = in.nextLine();
        for (int i=0;i<arrayList.size();i++)
        {
            Teacher teacher = new Teacher();
            teacher = (Teacher) arrayList.get(i);
            if(teacher.getName().equals(name))
            {
                System.out.println("请输入修改的姓名");
                String name1 = in.nextLine();
                System.out.println("请输入修改的账号");
                String user = in.nextLine();
                System.out.println("请输入修改的密码");
                String pwd = in.nextLine();
                teacher.setName(name1);
                teacher.setUser(user);
                teacher.setPwd(pwd);
                teacherFile.SaveTeacherFile(arrayList);
                break;
            }
        }
    }
    public void printpwd()
    {
        try {
            FileReader fr = new FileReader("manager.txt");
            BufferedReader sb = new BufferedReader(fr);
            String buf = null;
            while((buf=sb.readLine())!=null)
            {
                System.out.println("管理员密码："+buf);
            }
            fr.close();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }
    public String getPwd()
    {
        String buf= null;
        try {
            FileReader fr = new FileReader("manager.txt");
            BufferedReader sb = new BufferedReader(fr);
            buf=sb.readLine();
            fr.close();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        return buf;
    }
    public void findTeacherAll()
    {
        Scanner in = new Scanner(System.in);
        TeacherFile teacherFile = new TeacherFile();
        ArrayList arrayList = teacherFile.getArrayList();
        for(int i=0;i<arrayList.size(); i++)
        {
            Teacher teacher = new Teacher();
            teacher = (Teacher) arrayList.get(i);
            System.out.println(teacher.getName()+"\t"+teacher.getUser()+"\t"+teacher.getPwd());
        }
    }
    public void findTeacherOne()
    {
        Scanner in = new Scanner(System.in);
        TeacherFile teacherFile = new TeacherFile();
        ArrayList arrayList = teacherFile.getArrayList();
        System.out.println("请输入查询的老师姓名");
        String name = in.nextLine();
        for(int i=0;i<arrayList.size();i++)
        {
            Teacher teacher = (Teacher) arrayList.get(i);
            if(teacher.getName().equals(name))
            {
                System.out.println(teacher.getName()+"\t"+teacher.getUser()+"\t"+teacher.getPwd());
                break;
            }
        }
    }
}
